# -*- encoding: utf-8 -*-
'''
@File		:	ds.py
@Time		:	2024/07/18 09:46:08
@Author		:	dan
@Description:	使用 ai + 人工辅助，针对ds.h生成的python代码
'''

# ds.py
# Data sets
# This is a Python translation of the ds.h header file.

class ClockQuality:
    def __init__(self):
        pass
        # Add the properties and initializations related to ClockQuality if needed


class ClockIdentity:
    def __init__(self):
        pass
        # Add the properties and initializations related to ClockIdentity if needed


class PortIdentity:
    def __init__(self):
        pass
        # Add the properties and initializations related to PortIdentity if needed


class TimeInterval:
    def __init__(self):
        pass
        # Add the properties and initializations related to TimeInterval if needed


class FaultInterval:
    def __init__(self):
        pass
        # Add the properties and initializations related to FaultInterval if needed


# Constants for clock data sets
DDS_TWO_STEP_FLAG = 1 << 0
DDS_SLAVE_ONLY = 1 << 1

# Default Data Set structure
class DefaultDS:
    def __init__(self):
        self.flags = 0  # reserved（6）| slaveOnly（1） | twoStepFlag（1）
        self.reserved1 = 0
        self.number_ports = 0  # 表示当前PTP有多少个port端口
        self.priority1 = 0  # 用于计算最佳 master 时钟，值越低优先级越高
        self.clock_quality = ClockQuality()  # 时钟质量对象
        self.priority2 = 0  # 用于计算最佳 master 时钟，值越低优先级越高
        self.clock_identity = ClockIdentity()  # 时钟的唯一标识
        self.domain_number = 0
        self.reserved2 = 0

# Length of OUI (Organizationally Unique Identifier)
OUI_LEN = 3

# Clock Description structure
class ClockDescription:
    def __init__(self):
        self.product_description = ""  # static_ptp_text equivalent
        self.revision_data = ""  # static_ptp_text equivalent
        self.user_description = ""  # static_ptp_text equivalent
        self.manufacturer_identity = [0] * OUI_LEN  # Octet array

# Default DS structure
class DefaultDSConfig:
    def __init__(self):
        self.dds = DefaultDS()
        self.free_running = 0
        self.freq_est_interval = 0  # log seconds
        self.grand_master_capable = 0  # 802.1AS only
        self.stats_interval = 0  # log seconds
        self.kernel_leap = 0
        self.sanity_freq_limit = 0  # placeholder
        self.time_source = 0  # Enumeration8 equivalent, 用于描述grandmaster的时间源，数值越低 越精准，最低为原子震荡时钟

# Port Data Set structure
class PortDS:
    def __init__(self):
        self.port_identity = PortIdentity()  # 表示本地的时钟端口唯一标识
        self.port_state = 0  # Enumeration8 equivalent
        self.log_min_delay_req_interval = 0  # 发送 Delay_Req 的最小间隔
        self.peer_mean_path_delay = TimeInterval()  # P2P 网络里平均路径单向传输延迟的估值，如果 delayMechnism是END2END，那么这个值为0; 如果 delayMechanism 为 P2P, 该值有效
        self.log_announce_interval = 0  # Announce 消息发送间隔（s）的对数
        self.announce_receipt_timeout = 0  # Announce 接收超时时间（s）
        self.log_sync_interval = 0  # Sync 消息发送间隔（s）的对数
        self.delay_mechanism = 0  # Enumeration8 equivalent
        self.log_min_pdelay_req_interval = 0  # 发送 PDelayReq 的最小间隔
        self.version_number = 0  # 该协议的版本，一般为2

# Port Defaults structure
class PortDefaults:
    def __init__(self):
        self.asymmetry = 0
        self.log_announce_interval = 0
        self.log_sync_interval = 0  # sync 消息发送间隔(s)的对数
        self.log_min_delay_req_interval = 0  # 最小的Delay_Req 发送间隔（s）的对数
        self.log_min_pdelay_req_interval = 0  # 最小的PDelay_Req 发送间隔（s）的对数
        self.announce_receipt_timeout = 0
        self.sync_receipt_timeout = 0
        self.transport_specific = 0
        self.announce_span = 0
        self.path_trace_enabled = 0
        self.follow_up_info = 0
        self.freq_est_interval = 0  # log seconds
        self.flt_interval_pertype = [FaultInterval()] * FT_CNT  # Replace FT_CNT with actual count
        self.neighbor_prop_delay_thresh = 0  # nanoseconds
        self.min_neighbor_prop_delay = 0  # nanoseconds
        self.tx_timestamp_offset = 0  # 发送时获取时间所用的时间，文档中的 ingress 单位 nanoseconds
        self.rx_timestamp_offset = 0  # 接收时计算时间所用的时间，文档中的 egress 单位 nanoseconds

# FRI_ASAP constant
FRI_ASAP = -128
